/**
 * 贪吃蛇游戏主模块
 */
class SnakeGameApp {
  constructor() {
    // 初始化画布画
    this.canvas = document.getElementById('gameCanvas');
    this.canvas.width = 600;
    this.canvas.height = 600;
    
    // 初始化游戏
    this.game = new SnakeGame(this.canvas.width, this.canvas.height, 20);
    this.renderer = new GameRenderer(this.canvas, this.game);
    this.input = new GameInput(this.game);
    
    // 游戏循环
    this.lastTime = 0;
    this.gameLoop = this.gameLoop.bind(this);
    requestAnimationFrame(this.gameLoop);
  }
  
  gameLoop(timestamp) {
    // 更新游戏状态
    this.game.update(timestamp);
    
    // 渲染游戏
    this.renderer.render();
    
    // 继续游戏循环
    requestAnimationFrame(this.gameLoop);
  }
}

// 当页面加载完成后启动游戏
window.addEventListener('load', () => {
  new SnakeGameApp();
});